from CvPythonExtensions import *

import GerikSpells
from GerikSpells import GerikSpellBase
from GSGroupPolicies import GSAll as GSGroup
from GSHandlerPolicies import GSTargetting as GSHandler

from GSTargetInfoPolicies import GSSinglePlotTarget
from GSGraphicsPolicies import GSPlot

from GSResultsPolicies import GSPushMissionWithTarget as GSResults

import CvUtil



gc = CyGlobalContext()

PLOT_SQUARE_SIZE = 1

class BurnLand(GerikSpellBase, GSGroup, GSHandler, GSResults):
   def __init__(self):
      GerikSpellBase.__init__(self)
      GSGroup.__init__(self)
      
      stageList = []

      pPlotTargetPolicy = GSSinglePlotTarget(self.canTargetPlot)
      pPlotTargetPolicy.setCheckVisibility(False)
      pPlotGraphicsPolicy = GSPlot()
      pPlotGraphicsPolicy.setAffectedPlotColor("COLOR_RED", 1.0)
      stageList.append( (pPlotTargetPolicy, pPlotGraphicsPolicy) )


      GSHandler.__init__(self, stageList)
      GSResults.__init__(self, pPlotTargetPolicy)

   # Pre-spell-activation functions
   def canUnitCast(self, pCastingUnit, pPlot, bVisible):
      if (pCastingUnit.getUnitType() == gc.getInfoTypeForString("UNIT_WARRIOR")):
         return True

   # In-spell-activation Functions
   def canTargetPlot(self, pCastingGroup, pCastingPlot, pPotentialTarget, bVisible):
      return True
         

   # Post-spell-activation functions.
   def doSpellResults(self, pCastingGroup, pTargetInfo):
      CyEngine().triggerEffect(gc.getInfoTypeForString("EFFECT_EXPLOSION_01"), pTargetInfo.getTarget().getPoint())
      GSResults.doSpellResults(self, pCastingGroup, pTargetInfo)

   def doSpellResultsOnTarget(self, pCastingGroup, pTarget):
      pTarget.setPlotType(PlotTypes.PLOT_LAND, False, False)
      pTarget.setTerrainType(gc.getInfoTypeForString("TERRAIN_DESERT"), True, True)
       
